package com.ktdaddy.exception;

import com.ktdaddy.enums.ErrorCode;
import com.ktdaddy.json.JSON;

/**
 * @author kdaddy@163.com
 * @date 2021/7/15 22:51
 */
public class BaseErrorCode implements ErrorCode {
    private static final long serialVersionUID = 1L;
    private final int errorCode;
    private final String errorMsg;

    public BaseErrorCode(int errorCode, String errorMsg) {
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
    }

    public int getErrorCode() {
        return this.errorCode;
    }

    public String getErrorMsg() {
        return this.errorMsg;
    }

    public boolean equals(Object o) {
        if (this == o) {
            return true;
        } else if (!(o instanceof BaseErrorCode)) {
            return false;
        } else {
            BaseErrorCode that = (BaseErrorCode)o;
            if (this.getErrorCode() != that.getErrorCode()) {
                return false;
            } else {
                return this.errorMsg != null ? this.errorMsg.equals(that.errorMsg) : that.errorMsg == null;
            }
        }
    }

    public int hashCode() {
        int result = this.getErrorCode();
        result = 31 * result + (this.errorMsg != null ? this.errorMsg.hashCode() : 0);
        return result;
    }

    public String toString() {
        return JSON.toJSONString(this);
    }
}
